package com.itsu.app.controller;

import cn.hutool.core.convert.Convert;
import com.itsu.api.controllerApi.PublishControllerApi;
import com.itsu.app.service.AppPublishService;
import com.itsu.commons.annotations.MyCache;
import com.itsu.pojo.vo.PageResult;
import com.itsu.pojo.vo.QuanZiVo;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class PublishController implements PublishControllerApi {

    @Autowired
    AppPublishService appPublishService;

    @Override
    public ResponseEntity publishQunzi(String textContent, String location, String latitude, String longitude, MultipartFile[] multipartFiles) throws IOException {
        appPublishService.publish(textContent, location, latitude, longitude, multipartFiles);
        return ResponseEntity.ok(null);
    }

    @Override
    public ResponseEntity friendsQunzi(Integer page, Integer pagesize) {
        System.out.println("1");
        PageResult pageResult = appPublishService.friendsQunzi(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @Override
    public ResponseEntity recommendFriendQunzi(Integer page, Integer pagesize) {
        System.out.println("2");
        PageResult pageResult = appPublishService.recommendFriendQunzi(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @Override
    public ResponseEntity mySelfFriendQunzi(Integer page, Integer pageSize, Long userId) {
        PageResult pageResult = appPublishService.mySelfFriendQunzi(page, pageSize, userId);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 朋友圈点赞
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity likeMovements(@PathVariable("id") String publishId) {
        Long likeCount = appPublishService.likeMovements(publishId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 朋友圈取消点赞
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislikeMovements(@PathVariable("id") String publishId) {
        Long likeCount = appPublishService.dislikeMovements(publishId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 朋友圈喜欢
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity loveMovements(@PathVariable("id") String publishId) {
        Long loveCount = appPublishService.loveMovements(publishId);
        return ResponseEntity.ok(loveCount);
    }

    /**
     * 朋友圈取消喜欢
     * @param publishId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unLoveMovements(@PathVariable("id") String publishId) {
        Long loveCount = appPublishService.unLoveMovements(publishId);
        return ResponseEntity.ok(loveCount);
    }

    /**
     * 单条动态
     * @param publishId
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity movement(@PathVariable("id") String publishId) {
        QuanZiVo quanZiVo = appPublishService.findOneMovement(new ObjectId(publishId));
        return ResponseEntity.ok(quanZiVo);
    }


}
